package bloomers

/**
* Controls the view when a user wishes to see the seeds associated with their account
*/

class RegisteredSeedsController {

   def index() { 
        render(view:"index", model:[seedArray: session.user.seedArr])
    }
    
    /**
    * Allows search by any aspect of a seed by matching the search item with the seed params
    */
    
    
    def search = {
           
            def resultsMap = Seedz.search(params.q, params)
            render(view:'list',
                   model:[
                     seedInstanceList:resultsMap.results,
                     seedInstanceTotal:Seedz.countHits(params.q)
                   ] 
                  )
    }
    
    /**
    * Allows search by the scientific name of a seed by matching the search item with the seeds name
    */
    
     def searchScientificName = {
           
            def resultsMap = Seedz.search(params.q, properties: ["genus", "species"])
            render(view:'list',
                   model:[
                     seedInstanceList:resultsMap.results,
                     seedInstanceTotal:Seedz.countHits(params.q)
                   ] 
                  )
    }
    
    /**
    * Allows search by the hardiness zone of a seed by matching the search item with the seeds zone
    */
    
    def searchHardinessZone = {
            
            def resultsMap = Seedz.search(params.q, properties: ["hardiness"])
            render(view:'list',
                   model:[
                     seedInstanceList:resultsMap.results,
                     seedInstanceTotal:Seedz.countHits(params.q)
                   ] 
                  )
    }
    
}
